package aliyun

import (
	"api/utils/logger"
	openapi "github.com/alibabacloud-go/darabonba-openapi/client"
	alicloud "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
	"github.com/alibabacloud-go/tea/tea"
)

/**
 * @Description
 * @Author huan.wang
 * @Date 2021/4/30 1:26 下午
 **/

func CreateClient(accessKeyId *string, accessKeySecret *string) (result *alicloud.Client, err error) {
	config := &openapi.Config{
		AccessKeyId: accessKeyId,
		AccessKeySecret: accessKeySecret,
	}
	// 访问的域名
	config.Endpoint = tea.String("dysmsapi.aliyuncs.com")
	result = &alicloud.Client{}
	result, err = alicloud.NewClient(config)
	return result, err
}

func SendSMSCode(phone string, code string) error {
	client, err := CreateClient(tea.String("LTAI4Fj4XSBKGmynL9J4sCgb"), tea.String("5KlHgwzubwiZcYD7fwoHHxWIC7gaBR"))
	if err != nil {
		logger.Info.Println(err)
	}

	sendSmsRequest := &alicloud.SendSmsRequest{
		PhoneNumbers: tea.String("15552123897"),
		SignName:     tea.String(""),
		TemplateCode: tea.String("SMS_176529709"),
	}
	_, err = client.SendSms(sendSmsRequest)
	if err != nil {
		return err
	}
	return nil
}
